var cut[Nstate,Ncat-1];

model {
  for (i in 1:N){
    y[i] ~ dnorm(mu[i], 1)
    mu[i] <- b.state[stateID[i]] + b.1*chgUnemp1211[i] + b.2*avgUnemp12[i] + b.3*chgInc1211[i]+ b.4*inc12[i] + b.5*avgGas[i] + b.6*totForcAugOct[i] + b.7*younger30[i]+  b.8*older65[i] + b.9*female[i] + b.10*black[i] + b.11*latino[i] + b.12*noHighSchool[i] + b.13*HighSchool[i] + b.14*someCollege[i] + b.15*fourCollege[i] + b.16*income[i] + b.17*unemployed[i] + b.18*fullTime[i] + b.19*partTime[i] + b.20*ownHome[i] + b.21*newsInt[i] + b.22*ideol[i] + b.23*Dem[i] + b.24*Rep[i] + b.25*Ind[i]
    for (k in 1:(Ncat-1)) { logit(Q[i,k]) <- cut[stateID[i], k] - mu[i]}
    p[i, 1] <- Q[i,1]
    for (k in 2:(Ncat-1)){ p[i,k] <- Q[i,k] - Q[i, (k-1)]}
    p[i, Ncat] <- 1 - Q[i, (Ncat-1)]
  }
  for (j in 1:Nstate){
    b.state[j] ~ dnorm(mu.state, tau.state)
  }
  mu.state ~ dnorm(0, 0.0001)
  tau.state <- pow(sigma.state, -2)
  sigma.state ~ dunif(0, 1000)
  b.1 ~ dnorm(0, 0.0001)
  b.2 ~ dnorm(0, 0.0001)
  b.3 ~ dnorm(0, 0.0001)
  b.4 ~ dnorm(0, 0.0001)
  b.5 ~ dnorm(0, 0.0001)
  b.6 ~ dnorm(0, 0.0001)
  b.7 ~ dnorm(0, 0.0001)
  b.8 ~ dnorm(0, 0.0001)
  b.9 ~ dnorm(0, 0.0001)
  b.10 ~ dnorm(0, 0.0001)
  b.11 ~ dnorm(0, 0.0001)
  b.12 ~ dnorm(0, 0.0001)
  b.13 ~ dnorm(0, 0.0001)
  b.14 ~ dnorm(0, 0.0001)
  b.15 ~ dnorm(0, 0.0001)
  b.16 ~ dnorm(0, 0.0001)
  b.17 ~ dnorm(0, 0.0001)
  b.18 ~ dnorm(0, 0.0001)
  b.19 ~ dnorm(0, 0.0001)
  b.20 ~ dnorm(0, 0.0001)
  b.21 ~ dnorm(0, 0.0001)
  b.22 ~ dnorm(0, 0.0001)
  b.23 ~ dnorm(0, 0.0001)
  b.24 ~ dnorm(0, 0.0001)
  b.25 ~ dnorm(0, 0.0001)
  
  for (j in 1:(Nstate)){
    for (k in 1: (Ncat-1)){
      cut0[j,k] ~ dt(0, 1, 5)
    }
    cut[j,] <- sort(cut0[j,])
  }
}